<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 1.导包 -->
    <script src="./wangEditor.js"></script>
</head>

<body>
    <!-- 2.写html结构 -->
    <div id="div1" style="margin-top: 50px"></div>

    <button id="btn1">获取内容</button>
    <button id="btn2">设置内容</button>

    <script>
        /* 3.js初始化 */
        const E = window.wangEditor
        const editor = new E('#div1')
        // 或者 const editor = new E( document.getElementById('div1') )
        editor.create()


        //获取内容
        document.querySelector('#btn1').onclick = function(){
            console.log( editor.txt.text() );
            console.log( editor.txt.html() );
            
        };

        //设置内容
        document.querySelector('#btn2').onclick = function(){
            //替换内容
            // editor.txt.html('<h1>写的很好</h1><a href="#">双击666</a>'); 
            //追加内容
            editor.txt.append('<h1>写的很好</h1><a href="#">双击666</a>'); 
            
        };
    </script>
</body>

</html>